// pages/defect/craft/params/index.js
import {
  PARAMS_TYPE
} from '../../../../dataSource';

Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    form: {
      max: '',
      min: '',
      vals: []
    },
    name: '',

    paramsType: PARAMS_TYPE
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onCancel() {
      this.triggerEvent('cancel');
    },
    onSubmit(event) {
      if (this.data.form['vals'][0] && this.data.form['min'] && this.data.form['max']) {
        this.triggerEvent('submit', {
          ...event.detail.value,
          paramType: this.data.form['vals'][0],
          workmanshipParamGlazingId: this.data.id
        });
        return
      }
      wx.showToast({
        title: '未填写完表单',
        icon: 'none'
      })
    },
    initData(data) {
      this.setData(data)
    },
    setDefaultValue(form) {
      this.setData({
        form
      })
    },
    onSelect(event) {
      this.setData({

        form: {
          ...this.data.form,
          vals: event.detail
        }
      })
    },
    setParamsType(data) {
      this.setData({
        paramsType: data
      })
      this.onClear()
    },
    onInput(event) {
      const value = event.detail,
        key = event.currentTarget.dataset.key;
      const form = this.data.form;
      form[key] = value;
      this.setData({
        form
      })
    },
    onClear() {
      this.setData({
        form: {
          max: '',
          min: '',
          vals: []
        }
      })
    }
  }
})